home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pvbasics.h < prev    next >
C/C++ Source or Header  |  1998-01-05  |  5KB  |  171 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVBASICS.H                           |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     Basic and common-use stuff interface |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. //SET PROCESSING
  16.  
  17. #ifndef _PVBASICS_H
  18. #define _PVBASICS_H
  19.  
  20. #ifdef HDEBUG
  21.   #define NEW(x)        ( assert(_heapchk()==_HEAPOK),(new x)      )
  22.   #define MALLOC(x)     ( assert(_heapchk()==_HEAPOK),malloc(x)    )
  23.   #define REALLOC(x,y)  ( assert(_heapchk()==_HEAPOK),realloc(x,y) )
  24.   #define STRDUP(x)     ( assert(_heapchk()==_HEAPOK),strdup(x)    )
  25.   #define FREE(x)       ( assert(_heapchk()==_HEAPOK),free(x)      )
  26.   #define DELETE(x)     ( assert(_heapchk()==_HEAPOK),(delete x)   )
  27. #else
  28.   #define NEW(x)        (new x)
  29.   #define MALLOC(x)     malloc(x)
  30.   #define REALLOC(x,y)  realloc(x,y)
  31.   #define STRDUP(x)     strdup(x)
  32.   #define FREE(x)       free(x)
  33.   #define DELETE(x)     (delete x)
  34. #endif
  35.  
  36. #define lo(x) (*((char *)&(x)))    //low char of a word
  37. #define hi(x) (*((char *)&(x)+1))  //hi char of a word
  38. #define INCL(s,m) (s)[(m)>>3] |= (char)(1 << ((m)&7))
  39. #define EXCL(s,m) (s)[(m)>>3] &= (char)(~(1 << ((m)&7)))
  40. #define IN(s,m) (s)[(m)>>3] & ( 1 << ((m)&7))
  41.  
  42. #ifdef __386__
  43. #ifdef __FLAT__
  44. #define MKFP(segment,offset) (void*)FP_OFF(MK_FP(0,(segment<<4)+offset))
  45. #else
  46. #define MKFP(segment,offset) MK_FP(0,(segment<<4)+offset)
  47. #endif
  48. #else
  49. #define MKFP(segment,offset) MK_FP(segment,offset)
  50. #endif
  51.  
  52. #ifdef __386__
  53. #define INTR(i,inregs,outregs) int386(i,inregs,outregs)
  54. #define INTRX(i,inregs,outregs,segregs) int386x(i,inregs,outregs,segregs)
  55. #else
  56. #define INTR(i,inregs,outregs) int86(i,inregs,outregs)
  57. #define INTRX(i,inregs,outregs,segregs) int86x(i,inregs,outregs,segregs)
  58. #endif
  59.  
  60. #define BIOS_DTA(offset) MKFP(0x0040,offset)
  61. #define VGA_CHARS (char *)MKFP(0xA000,0x0000)
  62.  
  63. class Tset
  64. {
  65.   public:
  66.     char members[32];
  67.     void operator ~ ( void ); //clear the set
  68.     void operator ! ( void ); //[0..255]
  69.     int is_empty( void );
  70.     friend Tset& operator << ( Tset &set, uint member );
  71.     friend Tset& operator >> ( Tset &set, uint member );
  72.     friend Tset& operator << ( Tset &set, Tset &set1 );
  73.     friend Tset& operator >> ( Tset &set, Tset &set1 );
  74.     friend int operator &( Tset &set, uint member ); //return != 0 if member is in set
  75.     friend int operator &( uint member, Tset &set ); //return != 0 if member is in set
  76.     friend int operator == ( Tset &set1, Tset &set2 );
  77.     friend int operator != ( Tset &set1, Tset &set2 );
  78. };
  79.  
  80. inline int operator & ( Tset &set, uint member )
  81. {
  82.   return IN( set.members, member );
  83. }
  84.  
  85. inline int operator & ( uint member, Tset &set )
  86. {
  87.   return IN( set.members, member );
  88. }
  89.  
  90. inline Tset& operator << ( Tset &set, uint member )
  91. {
  92.   INCL( set.members, member );
  93.   return set;
  94. }
  95.  
  96. inline Tset& operator >> ( Tset &set, uint member )
  97. {
  98.   EXCL( set.members, member );
  99.   return set;
  100. }
  101.  
  102. inline int operator != ( Tset &set1, Tset &set2 )
  103. {
  104.   return !( set1 == set2 );
  105. }
  106.  
  107. inline int min( int x, int y ) { return ( (x < y) ? x : y ); }
  108. inline int max( int x, int y ) { return ( (x > y) ? x : y ); }
  109. inline uint minw( uint x, uint y ) { return ( (x < y) ? x : y ); }
  110. inline uint maxw( uint x, uint y ) { return ( (x > y) ? x : y ); }
  111. inline long minl( long x, long y ) { return ( (x < y) ? x : y ); }
  112. inline long maxl( long x, long y ) { return ( (x > y) ? x : y ); }
  113.  
  114. extern char rolb( char x, char num );
  115. #pragma aux rolb = \
  116.   "rol al,cl"      \
  117.   parm [al] [cl]   \
  118.   value [al]       \
  119.   modify [al];
  120.  
  121. extern char rorb( char x, char num );
  122. #pragma aux rorb = \
  123.   "ror al,cl"      \
  124.   parm [al] [cl]   \
  125.   value [al]       \
  126.   modify [al];
  127.  
  128. extern word rolw( word x, char num );
  129. #pragma aux rolw = \
  130.   "rol ax,cl"      \
  131.   parm [ax] [cl]   \
  132.   value [ax]       \
  133.   modify [ax];
  134.  
  135. extern word rorw( word x, char num );
  136. #pragma aux rorw = \
  137.   "ror ax,cl"      \
  138.   parm [ax] [cl]   \
  139.   value [ax]       \
  140.   modify [ax];
  141.  
  142. //TEXT PROCESSING
  143.  
  144. inline char cyr_toupper( char c )
  145. {
  146.   if( c>=0xA0 && c<=0xBF )
  147.     return (char)(c-0x20);
  148.   else
  149.     return c;
  150. }
  151.  
  152. inline char cyr_tolower( char c )
  153. {
  154.   if( c>=0x80 && c<=0x9F )
  155.     return (char) (c+0x20);
  156.   else
  157.     return c;
  158. }
  159.  
  160. #endif
  161.  
  162. void cyr_strupr( char *str );
  163. void cyr_strlwr( char *str );
  164.  
  165. //ROTATIONS
  166.  
  167. extern char rolb( char x, char num );
  168. extern char rorb( char x, char num );
  169. extern word rolw( word x, char num );
  170. extern word rorw( word x, char num );
  171.